# Contributor: Kaarle Ritvanen <kunkku@alpinelinux.org>
# Maintainer: Kaarle Ritvanen <kunkku@alpinelinux.org>
pkgname=dmvpn
pkgver=1.4.0
pkgrel=3
pkgdesc="Dynamic Multipoint VPN"
url="https://git.alpinelinux.org/cgit/dmvpn-tools/"
arch="noarch"
license="MIT"
_lua_dmvpn_deps="lua-asn1"
_dp_deps="lighttpd"
_ca_deps="lua5.2 lua5.2-lyaml lua5.2-ossl lua5.2-posix lua5.2-sql-sqlite3
	lua5.2-stringy lua-asn1"
makedepends="$_lua_dmvpn_deps $_dp_deps $_ca_deps"
depends="augeas bind-tools lua5.2 lua5.2-cqueues lua5.2-lyaml lua5.2-ossl
	lua5.2-posix lua5.2-struct lua-dmvpn quagga strongswan tunnel"
subpackages="dmvpn-ca dmvpn-crl-dp lua-dmvpn $pkgname-openrc"
options="!check"
source="$pkgname-$pkgver.tar.bz2::https://gitlab.alpinelinux.org/alpine/dmvpn-tools/-/archive/v1.4.0/dmvpn-tools-v1.4.0.tar.bz2
	dmvpn-ca.insync"
builddir="$srcdir/dmvpn-tools-v$pkgver"

package() {
	install -D -m 644 dmvpn.awall "$pkgdir"/usr/share/awall/optional/dmvpn.json
	install -D -m 644 dmvpn-hub.awall "$pkgdir"/usr/share/awall/optional/dmvpn-hub.json
	install -D dmvpn-pfx-decode "$pkgdir"/usr/libexec/dmvpn-pfx-decode
	install -D -m 644 dmvpn.charon "$pkgdir"/etc/strongswan.d/dmvpn.conf
	install -D -m 644 dmvpn.swanctl "$pkgdir"/etc/swanctl/conf.d/dmvpn.conf
	install -D nhrp-events "$pkgdir"/usr/sbin/nhrp-events
	install -D nhrp-events.initd "$pkgdir"/etc/init.d/nhrp-events
	install -D setup-dmvpn "$pkgdir"/usr/sbin/setup-dmvpn
}

ca() {
	depends="$_ca_deps lua-dmvpn"
	cd "$builddir"

	install -D dmvpn-ca "$subpkgdir"/usr/bin/dmvpn-ca
	install -D -m 644 dmvpn-ca.conf "$subpkgdir"/etc/dmvpn-ca.conf
	install -D -m 644 "$srcdir"/dmvpn-ca.insync "$subpkgdir"/etc/in-sync.d/dmvpn-ca
}

dp() {
	depends="$_dp_deps"

	local bin=/usr/bin/dmvpn-crl-update
	install -D "$builddir"/dmvpn-crl-update "$subpkgdir$bin"

	local dir=$subpkgdir/etc/periodic/15min
	mkdir -p "$dir"
	ln -s $bin "$dir"
}

dmvpn() {
	depends="$_lua_dmvpn_deps"

	cd "$builddir"
	install -D -m 644 dmvpn.lua "$subpkgdir"/usr/share/lua/5.2/dmvpn.lua
}

sha512sums="
9e930ce9adf3270263d2bdad3270e657e5b7cf2c4261a8f2086f2bdf61aa68ba070153247ba31d83080ae3599741ea41ee0724576c9fc68a2ba34f19bca4a543  dmvpn-1.4.0.tar.bz2
a2160b97ead95c0269005e6973b25315ec7f1eada9da70cda42a13e34c800eea836b8ef7723553ff0e751796ec0ae27efadbac6b9c66e7db944984d9ff387072  dmvpn-ca.insync
"
